//
//  MainTabBar.swift
//  SinaWeibo_18.1
//
//  Created by sun on 15/10/6.
//  Copyright © 2015年 孙美玲. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        
        //定义一个frame
        
        var index: CGFloat = 0
      
        let w = UIScreen.mainScreen().bounds.width / 5
        let h = self.bounds.height
        
        let frame = CGRectMake(0,0,w,h)
        
        for view in subviews {
        
            if view is UIControl && !(view is UIButton) {
            view.frame = CGRectOffset(frame, w * index , 0)
                
                index += (index == 1 ? 2:1)
                
            }
            composeButton.frame = CGRectOffset(frame, 2 * w, 0)
            
        }
        
        
    }
    
//懒加载按钮
    
    lazy var composeButton: UIButton = {
    let btn = UIButton(type: UIButtonType.Custom)
      btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
    
    self.addSubview(btn)
        return btn
    }()
    
    
    
    
    
    

}
